package databasetest.zx.com.databasetest.model;

/**
 * Created by zhoux on 2017/12/14.
 * 注释：
 */

public class TestThreadModel {

    // ①通过匿名内部类覆盖ThreadLocal的initialValue()方法，指定初始值
    private static ThreadLocal<Integer> seqNum = new ThreadLocal<Integer>() {
        public Integer initialValue() {
            return 0;
        }
    };
    private int num2 = 0;

    // ②获取下一个序列值
    public int getNextNum() {
        seqNum.set(seqNum.get() + 1);
        return seqNum.get();
    }// ②获取下一个序列值

    public int getNextNum2() {
        num2 = (num2 + 1);
        return num2;
    }
}
